<template>
	<ScorllRefresher @refresh="loadData">
		<view v-for="item of list" :key="item.spuId" class="iflex aic jcc fill"
			@click.stop="tapToServiceDetail(item.spuId)">
			<view class="iflex aic jcc fill item">
				<view class="iflex item__image">
					<image mode="aspectFill" :src="item.mainImgUrl"></image>
				</view>
				<view class="flex item__content">
					<view class="ellipsis-line-clamp3">
						{{item.spuName}}
					</view>
				</view>
			</view>
		</view>
	</ScorllRefresher>
</template>
<script lang="ts">
	import { defineComponent } from "vue";
	export default defineComponent({
		// #ifdef MP-WEIXIN
		options: {
			virtualHost: true,
			// styleIsolation: 'shared'
		},
		// #endif
	})
</script>
<script setup lang="ts">
	import ScorllRefresher from '@/components/scroll-refresher/scroll-refresher.vue';
	import { ServiceType } from '@/utils/constant';
	import { isEmpty } from '@/utils/util';
	import { getAllServiceList } from '@/apis/service';
	import { ref, watchEffect, computed, defineExpose } from 'vue';
	import type { AnyObj } from '@/types/global';
	const props = withDefaults(defineProps<{
		keyword : string;
	}>(), {
		keyword: ''
	});

	const list = ref<AnyObj[]>([]);
	function tapToServiceDetail(spuId : string) {
		uni.navigateTo({
			url: `/pages-service/service-detail/service-detail?spuId=${spuId}`
		})
	}

	function loadData() {
		const query : AnyObj = {};
		if (!isEmpty(props.keyword.trim())) {
			query.spuName = props.keyword.trim()
		}
		getAllServiceList(query).then((res) => {
			list.value = res.rows;
		});
	}

	watchEffect(() => {
		loadData();
	})


	defineExpose({
		search: loadData
	})
</script>

<style lang="scss" scoped>
	.item {
		padding: 0 30rpx;
		height: 160rpx;
		background: #FFF;

		&__image {
			width: 128rpx;
			height: 128rpx;

			image {
				width: 100%;
				height: 100%;
				object-fit: cover;
				border-radius: 10rpx;
			}
		}

		&__content {
			padding: 0 0 0 40rpx;
			font-size: 30rpx;
			font-weight: 400;
		}
	}
</style>